package com.woniuxy.consumerfeign.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.woniuxy.commons.entity.Goods;
import com.woniuxy.commons.service.ProviderService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author: yangtao
 * @date 2021/8/3 11:39
 * @Version 1.0
 */
@RestController
@RequestMapping("/feign")
public class FeignController {
    @Resource
    private ProviderService providerService;
    @HystrixCommand
    @GetMapping("/all")
    public List<Goods> all() throws InterruptedException {
    // 请求provider得到数据
        List<Goods> all = providerService.all();
        return all;
    }

    @GetMapping("/find")
    public Goods find(){
        Goods byId = providerService.findById(1004);
        return byId;
    }
    @GetMapping("/add")
    public boolean add(){
        Goods phone = new Goods(1005, "phone", 1000);
        boolean add = providerService.add(phone);
        return add;
    }

}
